// pages/cardbark/orderdetail/orderdetail.js
let app = getApp();
let testAddr = app.globalData.testAddr;
let imgurl = app.globalData.imgurl;
Page({

  /**
   * 页面的初始数据
   */
  data: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var orderID = options.orderID
    that.setData({
      orderID: orderID
    })
    that.paymoney()
    that.getorderdetail()
  },
  //付款进度
  paymoney: function() {
    var that = this;
    var jdArr = 0;
    var orderID = that.data.orderID
    app.util.request({
      url: testAddr + "payMent/getPayMent?orderID=" + orderID,
      method: "POST",
      data: {},
      success: function(res) {
        if (res.data.errorCode == 0 && res.data.errorCode != undefined) {
          var progresslist = res.data.result
          if (typeof progresslist != 'object' && progresslist != '') {
            progresslist = progresslist.replace(/\ufeff/g, ""); //重点
            var progresslist = JSON.parse(progresslist);
          }
          for (var i = 0; i < progresslist.length; i++) {
            jdArr = jdArr + progresslist[i].percent
          }
          that.setData({
            progresslist: progresslist,
            jdArr: jdArr,
          })
          // console.log(progresslist)
        }
      }
    })
  },
  // 获取订单详情
  getorderdetail: function() {
    var that = this
    var orderID = that.data.orderID
    app.util.request({
      url: testAddr + "facility_order/getOrderDetail?orderID=" + orderID,
      method: "POST",
      data: {},
      success: function(res) {
        var orderdetail = res.data
        var detailimg = imgurl + 'offer/' + res.data.offer.offerDetailImg
        that.setData({
          orderdetail: orderdetail,
          detailimg: detailimg
        })
        that.getlogisticsdetail()
        // console.log(detailimg)
        console.log(orderdetail)
      }
    })
  },
  // 获取物流详情
  getlogisticsdetail: function() {
    var that = this
    var companyNo = that.data.orderdetail.ecNo
    var searchNo = that.data.orderdetail.expressageNo
    app.util.request({
      url: testAddr + "expressage/getDetail?companyNo=" + companyNo + "&searchNo=" + searchNo,
      method: "POST",
      data: {},
      success: function(res) {
        var logistics = res.data
        for (var i = 0; i < logistics.length; i++) {
          logistics.list = logistics[i].list
        }
        that.setData({
          logistics: logistics,
        })
        // console.log(logistics)
        // console.log(logistics.list)
      }
    })
  },
  // 跳转公司
  tocompany:function(){
    var that =this
    var id = that.data.orderdetail.companyID
     wx.navigateTo({
       url: '../../detail/firm/firm?id=' + id,
     })
  },
  // 复制订单号
  copyorder: function(e) {
    if (e.currentTarget.dataset.ornumber) {
      var that = this;
      wx.setClipboardData({
        data: e.currentTarget.dataset.ornumber,
        success: function(res) {
          // self.setData({copyTip:true}),
          wx.getClipboardData({
            success: function (res) {
              wx.showToast({
                icon: 'none',
                title: '复制订单号成功',
                duration: 2000
              })
            }
          })
        }
      })
    }
    else{
      wx.showToast({
        icon: 'none',
        title: '不存在订单号'
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})